import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../util/request-util";
import {API} from "../../../constants/constants";
import {Observable} from "rxjs";
import {MsgResult} from "../../../models/msg-result";

@Injectable()
export class ResourcesService {

  constructor(
    private requestUtil: RequestUtil
  ) { }

    //无参查询资源
  getResources():Observable<MsgResult>{
    return this.requestUtil.get(API.getResources);
  }

  //添加资源
  insertResource(resource):Observable<MsgResult>{
    let params="name="+resource.name+"&url="+resource.url+"&isValid="+resource.isValid+"&isShow="+resource.isShow;
    return this.requestUtil.post(API.insertResource,params);
  }

  //删除资源
  deleteResource(id):Observable<MsgResult>{
    let params="id="+id;
    return this.requestUtil.get(API.deleteResource,params);
  }

  //根据id查询
  getResourcesById(id):Observable<MsgResult>{
    let params="id="+id;
    return this.requestUtil.get(API.getResourcesById,params);
  }

  //模糊查询
  getResourceByFuzzy(searchValue):Observable<MsgResult>{
    let params="searchValue="+searchValue;
    alert("搜索框输入的值：："+searchValue);
    // return this.requestUtil.get(API,params);
    return null;
  }

  //修改资源
  updateResource(resource):Observable<MsgResult>{
    let params="id="+resource.id+"&name="+resource.name+"&url="+resource.url+"&isValid="+resource.isValid+"&isShow="+resource.isShow;
    return this.requestUtil.post(API.updateResource,params);
  }
}
